package atguigu.cglib.demo2;

public class KidProxy extends Kid {

	private IMethordInterceptor mi;

	public KidProxy(IMethordInterceptor mi) {
		this.mi = mi;
	}

	@Override
	public void eat(Food food) {
		try {
			mi.intercept(this, //
				Kid.class.getMethod("eat", new Class[] { Food.class }), //
				new Object[] { food },//
				this.getClass().getMethod("eatProxy", //
				new Class[] { Food.class }));//
		} catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}
	}

	public void eatProxy(Food food) {
		super.eat(food);
	}

	@Override
	public void washhand() {
		try {
			mi.intercept(this, //
					Kid.class.getMethod("washhand", new Class[] {}), //
					new Object[] {},//
					this.getClass().getMethod("washhandProxy", //
					new Class[] {}));//
		} catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}
	}

	public void washhandProxy() {
		super.washhand();
	}

	@Override
	public void brushTeeth() {
		try {
			mi.intercept(this, //
				Kid.class.getMethod("brushTeeth", new Class[] {}),//
				new Object[] {},//
				this.getClass().getMethod("brushTeethProxy", //
				new Class[] {}));//
		} catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}
	}

	public void brushTeethProxy() {
		super.brushTeeth();
	}

}
